package com.zhiwang.planet.ui.main.v2

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.GridLayoutManager
import com.zhiwang.planet.R
import com.zhiwang.planet.databinding.FragmentGameListBinding
import com.zhiwang.planet.databinding.FragmentMobileBinding
import com.zhiwang.planet.databinding.FragmentMoneyListBinding
import com.zhiwang.planet.di.component.DaggerUserComponent
import com.zhiwang.planet.di.module.AccountModule
import com.zhiwang.planet.di.module.AutoDisposeModule
import com.zhiwang.planet.mvvm.viewmodel.ItemDecorationViewModel
import com.zhiwang.planet.mvvm.viewmodel.ListMoneyViewModel
import com.zhiwang.planet.mvvm.viewmodel.my.MobileViewModel
import com.zhiwang.planet.ui.BaseFragment
import kotlinx.android.synthetic.main.fragment_game_list.*
import javax.inject.Inject

class PokerFragment : BaseFragment() {


    @Inject
    lateinit var viewModel: ListMoneyViewModel


    @Inject
    lateinit var decoVm : ItemDecorationViewModel


    companion object {
        fun newInstance(): PokerFragment {
            val args = Bundle()

            val fragment = PokerFragment()
//            args.putString("type", type)
            fragment.arguments = args
            return fragment
        }
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        DaggerUserComponent.builder()
                .appComponent(getAppComponent())
                .autoDisposeModule(AutoDisposeModule(requireActivity()))
                .accountModule(AccountModule(requireActivity() as AppCompatActivity))
                .build()
                .inject(this)
    }


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val root = inflater.inflate(R.layout.fragment_game_list, container, false)

        val binding = DataBindingUtil.bind<FragmentGameListBinding>(root)
        binding?.lifecycleOwner = viewLifecycleOwner
        binding?.vm = viewModel
        binding?.decorVm = decoVm
        return root
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        moneyRecyclerView.layoutManager = GridLayoutManager(requireContext(), 3).apply {
            spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
                override fun getSpanSize(position: Int): Int {
                    return if (position == 0) 3
                    else 1
                }

            }
        }
        viewModel.type = "qipai"
        viewModel.loadGame()
    }
}